package com.immunology.service;

import java.util.Map;

import com.immunology.logic.validators.LoginFieldValidator;
import com.immunology.logic.validators.NameSurmameFieldsValidator;

public class UserRegistrationValidService extends RegistrationValidService {
	private static final String LOGIN = "login";
	private static final String PASSWORD = "password";
	private static final String CONFIRM_PASSWORD = "confirmPassword";
	private static final String FIRST_NAME = "firstName";
	private static final String MIDDLE_NAME = "middleName";
	private static final String LAST_NAME = "lastName";
	private static final String POST = "post";

	protected Map<String, String> parametersValidation(
			Map<String, String> parameters) {
		map = setNotNullParameters(parameters);
		LoginFieldValidator securityService = new LoginFieldValidator();
		boolean isValidLogin = securityService
				.generalValidateInRegistration(parameters.get(LOGIN));
		if (!isValidLogin) {
			map.put(LOGIN, WRONG_PARAMETER);
		}
		if (!parameters.get(PASSWORD).isEmpty()
				|| !parameters.get(CONFIRM_PASSWORD).isEmpty()) {
			isSamePassword(parameters);
		}
//		NameSurmameFieldsValidator validator = new NameSurmameFieldsValidator();
//
//		if (!validator.validate(parameters.get(FIRST_NAME))) {
//			map.put(FIRST_NAME, WRONG_PARAMETER);
//		}
//		if (!validator.validate(parameters.get(MIDDLE_NAME))) {
//			map.put(MIDDLE_NAME, WRONG_PARAMETER);
//		}
//		if (!validator.validate(parameters.get(LAST_NAME))) {
//			map.put(LAST_NAME, WRONG_PARAMETER);
//		}

		return map;
	}

	private void isSamePassword(Map<String, String> parameters) {
		String password = parameters.get(PASSWORD);
		String confirmPassword = parameters.get(CONFIRM_PASSWORD);

		boolean isSamePass = confirmPassword.equals(password);
		if (isSamePass == false) {
			map.put(PASSWORD, WRONG_PARAMETER);
			map.put(CONFIRM_PASSWORD, PASSWORD_MUST_BE_SAME);
		}
	}

}
